package com.imooc.miaosha.util;

import org.springframework.util.StringUtils;

import java.util.regex.Matcher;
import java.util.regex.Pattern;

/**
 * 模块描述: <br>
 * (参数校验工具类)
 *
 * @Author: Mr. xyb
 * @Date: 2019/4/17 0:04
 * @since: 1.8.0
 * @version: 1.0.0
 */
public class ValidatorUtils {

    /**
     * 手机校验正则
     * TODO 粗略版 需改进正则
     */
    private static final Pattern MOBILE_PATTERN = Pattern.compile("1\\d{10}");

    /**
     * 判断手机格式是否正确
     *
     * @param mobile
     * @return
     */
    public static Boolean isMobile(String mobile) {
        if (StringUtils.isEmpty(mobile)) {
            return false;
        }
        Matcher matcher = MOBILE_PATTERN.matcher(mobile);
        return matcher.matches();
    }
}
